package arrAndstr;

public class T125 {

    public static void main(String[] args) {

        String s = "\"A man, a plan, a canal: Panama\"";

        System.out.println(isPalindrome(s));

    }

    public static boolean isPalindrome(String s) {
        int len = s.length();

        int leftIndex = 1;
        int rightIndex = len-2;

        while(leftIndex <= rightIndex) {
            int leftCh = s.charAt(leftIndex);
            if(leftCh >= 'A' && leftCh <= 'Z') {
                leftCh = leftCh + 32;
            }
            if(!isThatChar(leftCh)) {
                leftIndex++;
                continue;
            }

            int rightCh = s.charAt(rightIndex);
            if(rightCh >= 'A' && rightCh <= 'Z') {
                rightCh = rightCh + 32;
            }
            if(!isThatChar(rightCh)) {
                rightIndex--;
                continue;
            }

            leftIndex++;
            rightIndex--;

            if(leftCh != rightCh) {
                return false;
            }
        }

        return true;
    }

    public static boolean isThatChar(int ch) {
        if((ch >= 'A' && ch<= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) {
            return true;
        }
        return false;
    }
}
